﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;

namespace DotNetNuke.Tests.UI.WatiN.SiteTests
{

    [TestFixture]

    public class UserMessagingTests : STBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {

            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        [DependsOn("Verify_user_Can_Send_Msg")]
        public void Verify_Unread_Messages_Appears_Upon_Login()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            
            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.Click();
            ieInstance.Refresh();
            MessagingModule msgModule = new MessagingModule(homePage);
            msgModule.ComposeMessage(TestUsers.User1.UserName, "Test Msg", "This is a test msg!", "Send");
       
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);

            //Assert
            Assert.IsTrue(loginPage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName + " (1)"));
        }

        [Test]
        public void Verify_Layout_And_Visibility_Of_User_Messaging_Module()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);

            //Log in as the user 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            loginPage.RegisterLink.Click();

            //Assert 
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.Text.Contains("User Profile"));
            Assert.IsTrue(homePage.ModuleTitleSpans.Count == 2);
            Assert.IsTrue(homePage.ModuleTitleSpans[0].Text.Contains("My Profile"));
            Assert.IsTrue(homePage.ModuleTitleSpans[1].Text.Contains("My InBox"));
            MessagingModule msgModule = new MessagingModule(homePage);
            Assert.IsTrue(msgModule.InboxTable.Exists);
            Assert.IsTrue(msgModule.ComposeLink.Exists);
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("My Messages"));
        }

        [Test]
        public void Verify_User_Can_Compose_New_Message()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.ClickNoWait();
            MessagingModule msgModule = new MessagingModule(homePage);
            msgModule.ComposeLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            //Assert 
            Assert.IsTrue(homePage.ModuleTitleSpan.InnerHtml.Contains("Preview Message"));
            Assert.IsTrue(msgModule.ToTextField.Exists);
            Assert.IsNull(msgModule.ToTextField.Text);
            Assert.IsTrue(msgModule.SubjectTextField.Exists);
            Assert.IsNull(msgModule.SubjectTextField.Text);
            Assert.IsTrue(msgModule.EditorTableWrap.Exists);
            Assert.IsTrue(msgModule.SendLink.Exists);
        }

        [Test]
        public void Verify_User_Can_Save_New_Msg_As_Draft()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.Click();
            MessagingModule msgModule = new MessagingModule(homePage);
            msgModule.ComposeMessage(TestUsers.User1.UserName, "Test Msg", "This is a test msg!", "Save");

            //Assert 
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(msgModule.GetMsgRowBySubject("[Draft] Test Msg").Exists);
            Assert.IsTrue(msgModule.GetMsgStatusBySubject("[Draft] Test Msg").InnerHtml.Contains("Draft"));

            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.IsTrue(homePage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName));
            Assert.IsFalse(homePage.RegisterLink.Text.Contains("(1)"));
        }

        [Test]
        public void Verify_User_Can_Delete_Msg_Saved_As_Draft()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.Click();
            MessagingModule msgModule = new MessagingModule(homePage);
            msgModule.ComposeMessage(TestUsers.User1.UserName, "Test Msg", "This is a test msg!", "Save");

            System.Threading.Thread.Sleep(1000);
            msgModule.GetMsgLinkBySubject("[Draft] Test Msg").Click();
            msgModule.DeleteMsgLink.Click();
            //Click PopUp
            msgModule.ConfirmDeleteButton.Click();


            //Assert 
            System.Threading.Thread.Sleep(1000);
            Assert.IsFalse(msgModule.InboxTable.InnerHtml.Contains("Test Msg"));

            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.IsTrue(homePage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName));
            Assert.IsFalse(homePage.RegisterLink.Text.Contains("(1)"));
        }

        [Test]
        public void Verify_User_Can_Cancel_While_Viewing_Msg_Saved_As_Draft()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.ClickNoWait();
            MessagingModule msgModule = new MessagingModule(homePage);
            msgModule.ComposeMessage(TestUsers.User1.UserName, "Test Msg", "This is a test msg!", "Save");

            System.Threading.Thread.Sleep(1000);
            msgModule.GetMsgLinkBySubject("[Draft] Test Msg").Click();
            Assert.IsTrue(msgModule.ToTextField.Text.Contains(TestUsers.User1.UserName));
            Assert.IsTrue(msgModule.SubjectTextField.Text.Contains("Test Msg"));
            msgModule.SubjectTextField.TypeText("NEW SUBJECT");
            msgModule.CancelMsgLink.Click();

            //Assert 
            System.Threading.Thread.Sleep(1000);
            Assert.IsFalse(msgModule.InboxTable.InnerHtml.Contains("NEW SUBJECT"));
            Assert.IsTrue(msgModule.GetMsgRowBySubject("[Draft] Test Msg").Exists);
            Assert.IsTrue(msgModule.GetMsgStatusBySubject("[Draft] Test Msg").InnerHtml.Contains("Draft"));

            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.IsTrue(homePage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName));
            Assert.IsFalse(homePage.RegisterLink.Text.Contains("(1)"));
        }

        [Test]
        public void Verify_user_Can_Send_Msg()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1500);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.Click();
            MessagingModule msgModule = new MessagingModule(homePage);
            string msgSubject = "Test Msg";
            string msgContent = "This is a test msg!";
            msgModule.ComposeMessage(TestUsers.User1.UserName, msgSubject, msgContent, "Send");

            //Assert 
            Assert.IsFalse(msgModule.InboxTable.InnerHtml.Contains(msgSubject));
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.IsTrue(loginPage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName + " (1)"));

            loginPage.RegisterLink.Click();
            Assert.IsTrue(msgModule.GetMsgRowBySubject(msgSubject).Exists);
            Assert.IsTrue(msgModule.GetMsgStatusBySubject(msgSubject).InnerHtml.Contains("Unread"));

            msgModule.GetMsgLinkBySubject(msgSubject).Click();
            Assert.IsTrue(msgModule.MsgContentDiv.InnerHtml.Contains(msgContent));
        }

        [Test]
        [DependsOn("Verify_user_Can_Send_Msg")]
        public void Verify_Unread_Messages_Decrements()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.Click();
            MessagingModule msgModule = new MessagingModule(homePage);
            string msg1Subject = "Test Msg";
            string msg2subject = "SecondMsg";
            string msg1Content = "This is msg 1";
            string msg2Content = "This is msg 2";
            msgModule.ComposeMessage(TestUsers.User1.UserName, msg1Subject, msg1Content, "Send");
            msgModule.ComposeMessage(TestUsers.User1.UserName, msg2subject, msg2Content, "Send");

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);

            //Assert
            Assert.IsTrue(loginPage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName + " (2)"));
            loginPage.RegisterLink.Click();
            msgModule.GetMsgLinkBySubject(msg1Subject).Click();

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            Assert.IsTrue(loginPage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName + " (1)"));
        }

        [Test]
        [DependsOn("Verify_user_Can_Send_Msg")]
        public void Verify_Unread_Messages_Increments()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.Click();
            MessagingModule msgModule = new MessagingModule(homePage);
            string msg1Subject = "Test Msg";
            string msg2subject = "SecondMsg";
            string msg1Content = "This is msg 1";
            string msg2Content = "This is msg 2";
            msgModule.ComposeMessage(TestUsers.User1.UserName, msg1Subject, msg1Content, "Send");

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            Assert.IsTrue(loginPage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName + " (1)"));
            loginPage.RegisterLink.Click();
            Assert.IsTrue(msgModule.GetMsgStatusBySubject(msg1Subject).InnerHtml.Contains("Unread"));

            //Send another msg
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            loginPage.RegisterLink.Click();
            msgModule.ComposeMessage(TestUsers.User1.UserName, msg2subject, msg2Content, "Send");

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);

            Assert.IsTrue(loginPage.RegisterLink.Text.Contains(TestUsers.User1.DisplayName + " (2)"));
            loginPage.RegisterLink.Click();
            Assert.IsTrue(msgModule.GetMsgStatusBySubject(msg1Subject).InnerHtml.Contains("Unread"));
            Assert.IsTrue(msgModule.GetMsgStatusBySubject(msg2subject).InnerHtml.Contains("Unread"));
        }

        [Test]
        [DependsOn("Verify_user_Can_Send_Msg")]
        public void Verify_User_Can_Reply_To_Msg()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Send a msg that the user can reply to 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.Click();
            MessagingModule msgModule = new MessagingModule(homePage);
            string msgSubject = "Test Msg";
            string msgContent = "This is a test msg!";
            msgModule.ComposeMessage(TestUsers.User1.UserName, msgSubject, msgContent, "Send");

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            loginPage.RegisterLink.Click();

            //Assert
            msgModule.GetMsgLinkBySubject(msgSubject).Click();
            msgModule.ReplyLink.Click();
            Assert.IsTrue(msgModule.ToTextField.Text.Contains(TestUsers.User2.UserName));
            Assert.IsTrue(msgModule.SubjectTextField.Text.Contains("RE:" + msgSubject));
            Assert.IsTrue(msgModule.ContentFrame.Html.Contains(TestUsers.User2.UserName + " wrote " + msgContent));

            string newContent = "This is a reply to your msg!";
            msgModule.HTMLEditorModeSpan.Click();
            System.Threading.Thread.Sleep(500);
            msgModule.htmlField.TypeText(newContent);
            msgModule.SendLink.Click();

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            loginPage.RegisterLink.Click();

            Assert.IsTrue(msgModule.GetMsgRowBySubject("RE:" + msgSubject).Exists);
            msgModule.GetMsgLinkBySubject("RE:" + msgSubject).Click();
            Assert.IsTrue(msgModule.MsgContentDiv.InnerHtml.Contains(newContent));
        }

        [Test]
        [DependsOn("Verify_user_Can_Send_Msg")]
        public void Verify_User_Can_Save_Draft_Of_Reply_To_Msg()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);
            System.Threading.Thread.Sleep(1500);

            //Send a msg that the user can reply to 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.Click();
            MessagingModule msgModule = new MessagingModule(homePage);
            string msgSubject = "Test Msg";
            string msgContent = "This is a test msg!";
            msgModule.ComposeMessage(TestUsers.User1.UserName, msgSubject, msgContent, "Send");

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            loginPage.RegisterLink.Click();
            msgModule.GetMsgLinkBySubject(msgSubject).Click();
            msgModule.ReplyLink.Click();

            //Act
            string newContent = "This is a reply to your msg!";
            msgModule.HTMLEditorModeSpan.Click();
            System.Threading.Thread.Sleep(500);
            msgModule.htmlField.TypeText(newContent);
            msgModule.SaveMsgLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert
            Assert.IsTrue(msgModule.GetMsgRowBySubject("[Draft] RE:" + msgSubject).Exists);
            Assert.IsTrue(msgModule.GetMsgStatusBySubject("[Draft] RE:" + msgSubject).InnerHtml.Contains("Draft"));
            msgModule.GetMsgLinkBySubject("[Draft] RE:" + msgSubject).Click();
            Assert.IsTrue(msgModule.ContentFrame.Html.Contains("This is a reply to your msg!"));

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            Assert.IsFalse(loginPage.RegisterLink.Text.Contains("(1)"));
        }


        [Test]
        [DependsOn("Verify_user_Can_Send_Msg")]
        public void Verify_User_Can_Cancel_Draft_Of_Reply_To_Msg()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add Users for testing
            UserPage users = new UserPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            users.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            users.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);

            //Send a msg that the user can reply to 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            homePage.RegisterLink.Click();
            MessagingModule msgModule = new MessagingModule(homePage);
            string msgSubject = "Test Msg";
            string msgContent = "This is a test msg!";
            msgModule.ComposeMessage(TestUsers.User1.UserName, msgSubject, msgContent, "Send");

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            loginPage.RegisterLink.Click();
            msgModule.GetMsgLinkBySubject(msgSubject).Click();
            msgModule.ReplyLink.Click();

            //Act
            string newContent = "This is a reply to your msg!";
            msgModule.HTMLEditorModeSpan.Click();
            System.Threading.Thread.Sleep(500);
            msgModule.htmlField.TypeText(newContent);
            msgModule.CancelMsgLink.Click();

            //Assert
            Assert.IsFalse(msgModule.InboxTable.InnerHtml.Contains("[Draft] RE:" + msgSubject));

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            Assert.IsFalse(loginPage.RegisterLink.Text.Contains("(1)"));
        }

        [Test]
        public void Verify_Layout_Visibility_Usability_Of_User_Messaging_With_nonEnglish_Language()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            
            ieInstance.GoTo(SiteURL + "/Host/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            LanguagePage languagePage = new LanguagePage(homePage);
            extensionsPage.InstallExtension(LanguagePath);

            ieInstance.GoTo(SiteURL + "/Admin/Languages.aspx");
            Image languageImage = ieInstance.Image(Find.ByAlt(LanguageCode));
            languageImage.Click();

            //Act 
            loginPage.RegisterLink.Click();

            //Assert 
            MessagingModule msgModule = new MessagingModule(homePage);
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains("My Messages"));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Mis Mensajes"));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Eliminar"));
            Assert.IsTrue(msgModule.ComposeLink.Text.Contains("Componer Nuevo Mensaje"));
            msgModule.ComposeLink.Click();
            Assert.IsTrue(msgModule.ModuleTitleSpan.InnerHtml.Contains("Previsualizar Mensaje"));
            Assert.IsTrue(msgModule.MsgContentDiv.InnerHtml.Contains("Validar Usuario"));
            Assert.IsTrue(msgModule.MsgContentDiv.InnerHtml.Contains("Para"));
            Assert.IsTrue(msgModule.MsgContentDiv.InnerHtml.Contains("Mensaje"));
        }

        #endregion

        #region Private Methods

     


        #endregion
    }
}
